package homework;

public class Random {
    public static void main(String[] args) {
        // 创建Random对象
        Random random = new Random();

        // 生成10个0到100之间的随机整数
        int[] numbers = new int[10];
        System.out.print("生成的随机数: ");
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = random.nextInt(101); // 0-100
            System.out.print(numbers[i] + " ");
        }
        System.out.println();

        // 计算平均值
        double average = calculateAverage(numbers);
        System.out.printf("平均值: %.2f\n", average);

        // 找出最大值和最小值
        int max = findMax(numbers);
        int min = findMin(numbers);
        System.out.println("最大值: " + max);
        System.out.println("最小值: " + min);
    }

    private int nextInt(int i) {
        return 0;
    }

    // 计算平均值的方法
    public static double calculateAverage(int[] array) {
        int sum = 0;
        for (int num : array) {
            sum += num;
        }
        return (double) sum / array.length;
    }

    // 找出最大值的方法
    public static int findMax(int[] array) {
        int max = array[0];
        for (int num : array) {
            if (num > max) {
                max = num;
            }
        }
        return max;
    }

    // 找出最小值的方法
    public static int findMin(int[] array) {
        int min = array[0];
        for (int num : array) {
            if (num < min) {
                min = num;
            }
        }
        return min;
    }
}
